<template>
  <div class="home" style="height:100%">
    <van-nav-bar
      title="观看记录"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
      fixed=true
    />
    <div class="historys">
      <h3>播放记录</h3>
    </div>
      <van-button size="small" type="primary" round  v-for="j in playhistory" :key="j" style="margin:5px" @click="href(j)">{{j.name}}{{j.title}}</van-button>
  </div>
</template>

<script>
// @ is an alias to /src
import { playHistory } from "../api/playHistory";
import {getRealPlayUrl} from '../api/getPlayUrl'
export default {
  name: "home",
  data: function() {
    return {
      src: "",
      searchCount: "",
      playhistory:[]
    };
  },
  components: {},
  mounted() {
    playHistory(localStorage.Imei).then(data =>{
      console.log(data)
      this.playhistory = data.data.data
    })
  },
  methods: {
    onClickLeft(){
      window.history.go(-1)
    },
    onSearch() {
      search(this.searchCount,localStorage.Imei).then((data) =>{
        if(data.data.data){
          this.$router.push(`/detail?name=${data.data.data.name}&key=${data.data.data.type}`)
        }else{
           this.$toast.fail('查询内容不存在');
        }
      })
    },
    href(j){
      getRealPlayUrl(j.qvodUrl,j.imei,j.name,j.title).then((data) =>{
        if(data.data.data){
          this.$router.push(`/play?url=${data.data.data}&name=${j.name}`)
        }else{
          this.$toast.fail('该资源不存在');
        }
      })
    },
  }
};
</script>
<style lang="scss" scoped>
.home{
  background: #ffffff;
}
.historys{
  width: 95% ;
  margin-top: 50px;
  h3{
    font-size: 16px;
    line-height: 32px;
    width: 100%;
  }
}
</style>
